home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group01b.txt / 000141_icon-group-sender_Thu Sep 6 12:55:23 2001.msg < prev    next >
Internet Message Format  |  2002-01-03  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id f86JsQ212824
  4.     for icon-group-addresses; Thu, 6 Sep 2001 12:54:26 -0700 (MST)
  5. Message-Id: <200109061954.f86JsQ212824@baskerville.CS.Arizona.EDU>
  6. From: Steve Wampler <swampler@noao.edu>
  7. X-Newsgroups: comp.lang.icon
  8. Subject: Re: join
  9. Date: Thu, 06 Sep 2001 09:58:35 -0700
  10. X-Complaints-To: abuse@noao.edu
  11. X-Accept-Language: en
  12. To: icon-group@cs.arizona.edu
  13. Errors-To: icon-group-errors@cs.arizona.edu
  14. Status: RO
  15. Content-Length: 1448
  16.  
  17. Andrew Hamm wrote:
  18. > dodod wrote in message <3B8C3D59.AA150BB8@hotmail.com>...
  19. > >hello
  20. > >i would like to write a program to emulate
  21. > >unix join command but i do not know how to start
  22. > >can you give me a hint or an example ?
  23. > >
  24. ....
  25. > I suppose it could also be programmed without the use of coroutines, but
  26. > where's the fun in that?
  27.  
  28. A *long* time ago I wrote a short program to "pair" the lines
  29. of two files using co-expressions (the basic stuff took 4 statements).
  30. Then I realized that the functionality the program was using from the co-expressions
  31. behavior is *exactly* the behavior provided by read()...
  32.  
  33. [A question for people: How equivalent are the following approaches?
  34.  
  35.     f := open(filename)
  36.     while line := read(f) do ...
  37.     close(f)
  38.  
  39. and
  40.  
  41.     cf := create (!(f := open(filename)) | (close(f),&fail))
  42.     while line := @cf do ...
  43.  
  44. ]
  45.  
  46. Anyway, switching to read() instead of coroutines cut the basic
  47. algorithm down to 2 statements.
  48.  
  49. Here's the basic algorithm for this "pairing":
  50.  
  51.     # Output pairs of lines from files f1 and f2, where each pair
  52.     #    is joined on a single output line.
  53.     #
  54.     procedure pair(f1, f2)
  55.         while write( read(f1), read(f2)|"")
  56.         while write( read(f2) )
  57.     end
  58.  
  59. join's basic algorithm isn't much worse, but there's a lot of
  60. ugliness to handle the fields [still cleaner than in C, I imagine!].
  61.     
  62. --
  63. Steve Wampler-  SOLIS Project, National Solar Observatory
  64. swampler@noao.edu
  65.